Skip to content

feat: expose getAnonymousId()#31

Merged
choudlet merged 4 commits into
mainfrom
chrish/sc-37839/feat-expose-getanonymousid-as-public
Apr 21, 2026
Merged

feat: expose getAnonymousId()#31
choudlet merged 4 commits into
mainfrom
chrish/sc-37839/feat-expose-getanonymousid-as-public

Conversation

@choudlet

@choudlet choudlet commented Apr 15, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds getAnonymousId(): Promise<string> to the public AnalyticsInterface
  • Returns the anonymous ID from the JS IdentityManager — guaranteed non-null after init() (loaded from AsyncStorage, generated UUID, or timestamp-based fallback)
  • Async, never returns null, properly awaitable
  • Pre-bind proxy calls queue and resolve after bind; post-bind calls forward immediately

Ticket: SC-37839

What changed

Public API

  • AnalyticsInterface in types.ts: added getAnonymousId: () => Promise<string>

Design decision

The anonymous ID is managed entirely in JS via IdentityManager, which persists to AsyncStorage and always guarantees a value after initialization. No native bridge modules are needed — this avoids unnecessary complexity and platform-specific code for something the JS layer already handles.

Test plan

  • MetaRouterAnalyticsClient.test.ts — 2 new tests: returns JS IdentityManager value, is async and returns a string (never null)
  • proxyClient.test.ts — 2 new tests: pre-bind queuing + post-bind forwarding; "forwards all methods" updated
  • init.test.ts — asserts getAnonymousId exposed on returned client
  • All 189 tests pass
  • TypeScript compiles with no errors

Add getAnonymousId(): Promise<string | null> to AnalyticsInterface,
delegating to the native MetaRouter SDK identity layer via a new
MetaRouterIdentity bridge module on both iOS and Android.

- Add MetaRouterIdentityModule (Android) and MetaRouterIdentity (iOS)
  native bridge modules with getAnonymousId method
- Add NativeIdentity.ts JS wrapper with fault-tolerant bridge access
- Wire getAnonymousId through MetaRouterAnalyticsClient, init binding,
  and proxy (async-queued pre-bind, immediate post-bind)
- Resolve null for missing/unavailable native module (no rejection)
@choudlet choudlet changed the title feat: anon_id [rn] feat: expose getAnonymousId() Apr 15, 2026

@brandon-metarouter brandon-metarouter left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a type comment, otherwise looks good!

* Guaranteed non-null after init() — the IdentityManager always generates
* or loads an anonymous ID before the client reaches the 'ready' state.
*/
async getAnonymousId(): Promise<string> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be returning: Promise<string|null>? I took a peek at IdentityManager.getAnonymousId and it's return type says null is possible.

  /**
   * Retrieves the current anonymous ID.
   * @returns The anonymous ID or null if not initialized.
   */
  getAnonymousId(): string | null {
    return this.anonymousId;
  }

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to be in line with other SDKs and awaiting the string. So it's always going to be a string.

Comment thread src/analytics/types.ts
reset: () => Promise<void>;
enableDebugLogging: () => void;
getDebugInfo: () => Promise<Record<string, any>>;
getAnonymousId: () => Promise<string>;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, should this be Promise<string|null> ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

@choudlet choudlet merged commit f71abbf into main Apr 21, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants